package com.topone.controller;

import com.topone.Enum.CouponEnum;
import com.topone.Exception.FanZoneException;
import com.topone.Utils.ResultVOUntil;
import com.topone.VO.ResultVO;
import com.topone.dataObject.Mapper.CouponMapper;
import com.topone.dto.BussinessDTO;
import com.topone.dto.CouponDTO;
import com.topone.dto.TcCouponDTO;
import com.topone.dto.TcUserCouponDTO;
import com.topone.service.TcCouponService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2018/1/27,0027.
 */
@Controller
@RequestMapping("/buyer/payment")
@Slf4j
public class  BuyerPaymentController {

    @Autowired
    private TcCouponService tcCouponService;

    @GetMapping("/prePay")
    @Transactional
    public ResultVO prePay(@RequestParam("bussinessId") String bussinessId,
                           @RequestParam("couponId") String couponId,
                               @RequestParam("openid")String openid,
                           Map<String, Object> map){

        if(StringUtils.isEmpty(bussinessId) && StringUtils.isEmpty(couponId)){
            log.error("【待付款】失败 bussinessName={},couponId={}",bussinessId,couponId);
            return ResultVOUntil.error(1,"bussinessName和couponIdO参数不正确");
        }
        try {
            List<TcCouponDTO> couponList= tcCouponService.paymentCoupon(bussinessId,couponId);
            List<TcUserCouponDTO> userCouponDTOList=tcCouponService.findphoneBycouponId(couponId,openid);
            map.put("couponList",couponList);
            map.put("userCouponDTOList",userCouponDTOList);
        }catch (FanZoneException e){
            log.error("【待付款】相关信息查询失败 e={}",e.getMessage());
            return ResultVOUntil.error(1,e.getMessage());
        }

        map.put("success","【待付款】成功");
        log.info("【待付款】相关信息查询成功,{}",map);
      return ResultVOUntil.success(map);
    }
}
